package com.easy.base.api.model.dto;

import com.easy.base.api.model.enums.ShowType;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@JsonInclude(value = JsonInclude.Include.NON_EMPTY, content = JsonInclude.Include.NON_NULL)
@ApiModel("ResultBody")
public class ResultBody<T> {

    public static <T> ResultBody<T> Success(boolean success) {
        ResultBody<T> body = new ResultBody<>();
        body.setSuccess(success);
        body.setData(null);
        body.setErrorCode("");
        body.setErrorMessage("");
        body.setShowType(ShowType.Silent);
        body.setTraceId("");
        body.setHost("");
        return body;
    }

    public static <T> ResultBody<T> Success(boolean success, T data) {
        ResultBody<T> body = new ResultBody<>();
        body.setSuccess(success);
        body.setData(data);
        body.setErrorCode("");
        body.setErrorMessage("");
        body.setShowType(ShowType.Silent);
        body.setTraceId("");
        body.setHost("");
        return body;
    }

    public static <T> ResultBody<T> Error(boolean success, String errorCode, String errorMessage, int showType) {
        ResultBody<T> body = new ResultBody<>();
        body.setSuccess(success);
        body.setData(null);
        body.setErrorCode(errorCode);
        body.setErrorMessage(errorMessage);
        body.setShowType(showType);
        body.setTraceId("");
        body.setHost("");
        return body;
    }

    @JsonProperty(index = 1)
    @ApiModelProperty("if request is success")
    private boolean success;

    @JsonProperty(index = 2)
    @ApiModelProperty("response data")
    private T data;

    @JsonProperty(index = 3)
    @ApiModelProperty("code for errorType")
    private String errorCode;

    @JsonProperty(index = 4)
    @ApiModelProperty("message display to user")
    private String errorMessage;

    @JsonProperty(index = 5)
    @ApiModelProperty("error display type")
    private int showType;

    @JsonProperty(index = 6)
    @ApiModelProperty("Convenient for back-end Troubleshooting: unique request ID")
    private String traceId;

    @JsonProperty(index = 7)
    @ApiModelProperty("onvenient for backend Troubleshooting: host of current access server")
    private String host;
}
